﻿using System;
using System.Linq;
using Randomize.Core.Descriptors;

namespace Randomize.Sample
{
    public class PersonDescriptor : ComplexTypeDescriptor<Person>
    {
        public PersonDescriptor()
        {
            this.Property(p => p.Age)
                .WithMin(18)
                .WithMax(80);

            this.Property(p => p.Name)
                .WithPool(new []{"John", "Andy", "Charlie"})
                .WithLength(10);

            this.Property(p => p.Salary)
                .WithMax(2000)
                .WithMin(800)
                .WithFractional(2);

            this.Property(p => p.BirthDate)
                .WithMin(new DateTime(1960, 1, 1))
                .WithMax(DateTime.Now)
                .IgnoreTime();

            this.Property(p => p.ChildrenCount,
                          new Action<Person, int>((person, number) => person.ChildrenCount = (byte) number))
                .WithMin(0)
                .WithMax(10);

            this.Collection(new IntDescriptor()
                                .WithMax(10)
                                .WithMin(0),
                            (person, items) => person.Items = items.ToList());

            this.Property(p => p.Gender)
                .WithGenerator(random => new GenderGenerator());

            this.CreateUsing(() => new Person());
        }
    }

    public class EmployeeDescriptor : ComplexTypeDescriptor<Employee>
    {
        public EmployeeDescriptor()
        {
            this.Property(p => p.Name)
                .WithPool(new[] {"John", "Andy", "Carl"});

            this.Property(p => p.Salary,
                          (person, salary) => person.Salary = salary*1000) //override property setter
                .WithMin(1)
                .WithMax(3)
                .WithFractional(1);

            this.Property(p => p.BirthDate)
                .WithMin(new DateTime(1940, 1, 1))
                .WithMax(DateTime.Now.AddYears(-18))//we're not hiring children:)
                .IgnoreTime();

            this.CreateUsing(() => new Employee()); //set up constructing function to avoid Activator.CreateInstance() usage;
        }
    }
}
